package com.ruoyi.yf.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.yf.mapper.YfYcgxMapper;
import com.ruoyi.yf.domain.YfYcgx;
import com.ruoyi.yf.service.IYfYcgxService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * ZD医废处置机构、医疗机构关系Service业务层处理
 * 
 * @author ZhaoDan...
 * @date 2021-06-18
 */
@Service
public class YfYcgxServiceImpl implements IYfYcgxService 
{
    @Autowired
    private YfYcgxMapper yfYcgxMapper;
    @Autowired
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询ZD医废处置机构、医疗机构关系
     * 
     * @param id ZD医废处置机构、医疗机构关系ID
     * @return ZD医废处置机构、医疗机构关系
     */
    @Override
    public YfYcgx selectYfYcgxById(Long id)
    {
        return yfYcgxMapper.selectYfYcgxById(id);
    }

    /**
     * 查询ZD医废处置机构、医疗机构关系列表
     * 
     * @param yfYcgx ZD医废处置机构、医疗机构关系
     * @return ZD医废处置机构、医疗机构关系
     */
    @Override
    public List<YfYcgx> selectYfYcgxList(YfYcgx yfYcgx)
    {
        return yfYcgxMapper.selectYfYcgxList(yfYcgx);
    }

    /**
     * 新增ZD医废处置机构、医疗机构关系de a
     *
     * 
     * @param yfYcgx ZD医废处置机构、医疗机构关系
     * @return 结果
     */
    @Override
    @Transactional
    public int insertYfYcgx(YfYcgx yfYcgx)
    {
        yfYcgx.setCreateTime(DateUtils.getNowDate());
        yfYcgx.setUpdateTime(DateUtils.getNowDate());
        Date startSigningDate = yfYcgx.getStartSigningDate();
        Date endSigngingDate = yfYcgx.getEndSigngingDate();
        Date nowDate = DateUtils.getNowDate();
        //当前时间
        long n = nowDate.getTime();
        //签约开始时间
        long start = startSigningDate.getTime();
        //签约结束时间
        long end = endSigngingDate.getTime();
        if(start < end && end > n) {
            SysDept dept = new SysDept();
            dept.setDeptId(yfYcgx.getHospitalId());
            dept.setSignStatus("1");
            sysDeptMapper.updateDept(dept);
        }
        //把签约记录添加到yf_ycgx
        return yfYcgxMapper.insertYfYcgx(yfYcgx);
    }

    /**
     * 修改ZD医废处置机构、医疗机构关系
     * 
     * @param yfYcgx ZD医废处置机构、医疗机构关系
     * @return 结果
     */
    @Override
    public int updateYfYcgx(YfYcgx yfYcgx)
    {
        yfYcgx.setUpdateTime(DateUtils.getNowDate());
        return yfYcgxMapper.updateYfYcgx(yfYcgx);
    }

    /**
     * 删除ZD医废处置机构、医疗机构关系对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteYfYcgxByIds(String ids)
    {
        return yfYcgxMapper.deleteYfYcgxByIds(Convert.toStrArray(ids));
    }

}
